﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wd_33_f1_shortcut_v1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Window_Loaded);
        }

        void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.PreviewKeyDown += new KeyEventHandler(Window_PreviewKeyDown3);

        }

        //方法三：直接调用pdf
        void Window_PreviewKeyDown3(object sender, KeyEventArgs e)
        {
            if (Key.F1 == e.Key)
            {
                //MessageBox.Show("F1");
                try
                {
                    string path = @"readme.pdf";
                    System.Diagnostics.Process.Start(path);
                }
                catch (Exception ex)
                {
                    //Cursor.Current = Cursors.Default;
                    //Utils.ShowMessageBox(App.GetString("ID_LG_25"), false, true);
                    //MainWindow.ErrorMessagee("HelpDocument->OpenHelpDoc", ex);
                    MessageBox.Show(ex.Message);
                }
            }
            else if (Key.F2 == e.Key)
            {
                MessageBox.Show("F2");
            }
        }

        //方法二：WebBrowser
        void Window_PreviewKeyDown2(object sender, KeyEventArgs e)
        {
            if (Key.F1 == e.Key)
            {
                //MessageBox.Show("F1");
                try
                {
                    string path = @"readme.pdf";
                    theBrowser.Navigate(path);  //报错：无效的URI
                }
                catch (Exception ex)
                {
                    //Cursor.Current = Cursors.Default;
                    //Utils.ShowMessageBox(App.GetString("ID_LG_25"), false, true);
                    //MainWindow.ErrorMessagee("HelpDocument->OpenHelpDoc", ex);
                    MessageBox.Show(ex.Message);
                }
            }
            else if (Key.F2 == e.Key)
            {
                MessageBox.Show("F2");
            }
        }


        void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (Key.F1 == e.Key)
            {
                //MessageBox.Show("F1");
                try
                {
                    string path = "readme.pdf";
                    System.Diagnostics.Process.Start(@"SumatraPDF-3.3.3-64.exe", "\"" + path + "\"");
                }
                catch (Exception ex)
                {
                    //Cursor.Current = Cursors.Default;
                    //Utils.ShowMessageBox(App.GetString("ID_LG_25"), false, true);
                    //MainWindow.ErrorMessagee("HelpDocument->OpenHelpDoc", ex);
                    MessageBox.Show(ex.Message);
                }
            }
            else if (Key.F2 == e.Key)
            {
                MessageBox.Show("F2");
            }                 
        }
    }
}
